import os.path
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

# 语法:wedbriver.send.keys(文件路径)
# os.path.abspath(__file__)  #C:\Users\年轻人\Desktop\web自动化丹\liudan-web-automation\day4\day4课上代码\05-弹窗处理.py
# os.path.dirname(os.path.abspath(__file__))  #C:\Users\年轻人\Desktop\web自动化丹\liudan-web-automation\day4\day4课上代码
# dirname  找当前文件的目录
# exit 退出
driver = webdriver.Chrome()
file = 'file:///' + os.path.abspath('html3') + '/upload_file.html'
driver.get(file)

file1 = os.path.dirname(os.path.abspath(__file__)) + "/01-alert弹窗.py"
time.sleep(2)
driver.find_element(By.NAME, "file").send_keys(file1)
time.sleep(2)
driver.quit()